/*
 * Copyright 2023 DSAL, HUST.
 */
#ifndef _LINUX_DB_H
#define _LINUX_DB_H 

#include "dbcache.h"
#include "acache.h"
#include "btree.h"
#include "debug.h"
#include "request.h"
#include "writeback.h"

#include <linux/time.h>
#include <linux/module.h>
#include <linux/hash.h>
#include <linux/random.h>
#include <linux/backing-dev.h>

#define REQ_DB_COLD (__REQ_NR_BITS+1)
enum req_flag_db {
    __REQ_DB_DATA = __REQ_NR_BITS + 1, // 26
    __REQ_DB_MAIN,
    __REQ_DB_SYSTEM,
    __REQ_DB_LOG,
    __REQ_DB_TEMP,
    __REQ_DB_ROLL,
};
#define REQ_DB_DATA     (1ULL << __REQ_DB_DATA) // 67108864
#define REQ_DB_MAIN     (1ULL << __REQ_DB_MAIN) // 134217728
#define REQ_DB_SYSTEM   (1ULL << __REQ_DB_SYSTEM) // 268435456
#define REQ_DB_LOG      (1ULL << __REQ_DB_LOG) // 536870912
#define REQ_DB_TEMP     (1ULL << __REQ_DB_TEMP) // 1073741824
#define REQ_DB_ROLL     (1ULL << __REQ_DB_ROLL) // 2147483648
#define REQ_DB_MASK     (REQ_DB_DATA | REQ_DB_MAIN | REQ_DB_SYSTEM | REQ_DB_LOG | REQ_DB_TEMP | REQ_DB_ROLL)

bool get_bio_flag(struct bio *bio, unsigned int FLAG);
__u32 hotness_get(struct cached_dev *dc, struct bio *bio);
void hotness_update(struct cached_dev *dc, struct bio *bio);
unsigned int hotness_get_type(struct cached_dev *dc, struct bio *bio);
void hotness_reset(struct cached_dev *dc, struct bio *bio);

#endif
